class Juxing {
  constructor(ctx, startX, startY, color) {
    this.startX = startX
    this.startY = startY
    this.endX = startX
    this.endY = startY
    this.color = color
    this.ctx = ctx
  }
  get minX() {
    return Math.min(this.startX, this.endX)
  }
  get maxX() {
    return Math.max(this.startX, this.endX)
  }
  get minY() {
    return Math.min(this.startY, this.endY)
  }
  get maxY() {
    return Math.max(this.startY, this.endY)
  }
  draw() {
    this.ctx.beginPath()
    this.ctx.moveTo(this.minX, this.minY)
    this.ctx.lineTo(this.minX, this.maxY)
    this.ctx.lineTo(this.maxX, this.maxY)
    this.ctx.lineTo(this.maxX, this.minY)
    this.ctx.closePath()
    this.ctx.fillStyle = this.color
    this.ctx.fill()
    this.ctx.strokeStyle = '#fff'
    this.ctx.lineWidth = 2
    this.ctx.stroke()
  }
  isInside(mouseX, mouseY) {
    return mouseX >= this.minX && mouseX <= this.maxX && mouseY >= this.minY && mouseY <= this.maxY
  }
}
export default Juxing
